
//
// 101019 - AH - First check in to google project.
// 101020 - AH - Removed explicit name attribute here, uses AttributeObject's,
//               see AttributeObject.201020.
// 101111 - AH - getNetwork().
// 101114 - AH - getLinkage().
// 110606 - AH - (Garage) getSoekratName().
// 110610 - AH - (Augustine *) setName() override here. 
//

package org.soekrat.engine.network;

import org.soekrat.AttributeObject;
import org.soekrat.engine.SoekratName;

/**
 * <p>
 *   A node in a
 *   {@link Network}.
 * </p> 
 * @author Arne Halvorsen (AH)
 * @author Laetitia Le Chatton (LLC) 
 */
public final class NetworkNode extends AttributeObject 
  implements Comparable<NetworkNode>
{
  private final Network m_network;
  
  private SoekratName m_sname;
  
  /**
   * <p>
   *   Constructor.
   * </p>
   * @param name Name associated with node.
   */
  NetworkNode(String name, Network network)
  { 
    if (name==null)
    {
      throw new NullPointerException("name");
    }
    if (network==null)
    {
      throw new NullPointerException("network");
    }
    
    m_sname=new SoekratName(name);
    super.setName(m_sname.getPure());
     
    m_network=network; 
  }
  
  public void setName(String name)
  {
    if (name==null)
    {
      throw new NullPointerException("name");
    }
    
    m_sname=new SoekratName(name);
    
    super.setName(m_sname.getPure());
  }
  
  /**
   * <p>
   *   Gets
   *   {@link SoekratName} that was created for {@code this} from 
   *   {@link String} passed to
   *   {@link #NetworkNode(String, Network)}.
   * </p>
   * @return {@link SoekratName}.
   */
  public SoekratName getSoekratName(){ return m_sname; }
  
  /**
   * <p>
   *   Gets
   *   {@link Network} {@code this} belongs to.
   * </p>
   * @return {@code Network}.
   */
  public Network getNetwork(){ return m_network; }
  
  @Override
  public String toString(){ return getName(); }
  
  @Override
  public int compareTo(NetworkNode o)
  { 
    return getName().compareTo(o.getName());
  }
  
  /**
   * <p>
   *   Gets linkage for {@code this} node.
   * </p>
   * @return Linkage.
   * @see Network#getLinkage(NetworkNode).
   */
  public int getLinkage(){ return m_network.getLinkage(this); }
  
  /**
   * <p>
   *   The empty array shared.
   * </p>
   */
  public final static NetworkNode[] E_ARRAY=new NetworkNode[0];
  
}
